class Solution {
public:
    int uniquePaths(int m, int n) {
        swap(n, m);
        vector<vector<int>>f(n + 1, vector<int>(m, 0));
        f[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!i && !j)continue;
                else if (!i) f[i][j] += f[i][j - 1];
                else if (!j) f[i][j] += f[i - 1][j];
                else {
                    f[i][j] += f[i - 1][j];
                    f[i][j] += f[i][j - 1];
                }
            }
        }
        return f[n - 1][m - 1];
    }
};